import * as echarts from 'echarts'
export default function useCharts(el: HTMLElement) {
  const instance = echarts.init(el)
  const setOptions = (options: echarts.EChartsCoreOption) => {
    instance.setOption(options)
  }
  // echarts重新渲染
  const resize = () => instance.resize()

  // 容器尺寸变化重新渲染
  window.addEventListener('resize', resize, false)
  onUnmounted(() => {
    instance?.dispose()
    window.removeEventListener('resize', resize, false)
  })

  return { setOptions, resize }
}
